import resources.RegistNetPropertyBundle;

/* [start] 	initializes gui variables */
RegistNetPropertyBundle bundle = RegistNetPropertyBundle.getInstance("/resources/registnet");

String _logo =  bundle.getProperty("registnet.logo");

String _registrar = bundle.getProperty("registnet.login.form.user.registrar");

String _authors = bundle.getProperty("registnet.user.registrar.toolbar.authors");
String _help = bundle.getProperty("registnet.user.registrar.toolbar.help");

String _welcome = bundle.getProperty("registnet.user.registrar.welcome");
String _sign_out = bundle.getProperty("registnet.user.registrar.sign_out");
String _my_account = bundle.getProperty("registnet.user.registrar.my_account");
String _home = bundle.getProperty("registnet.user.registrar.home");
String _menu = bundle.getProperty("registnet.user.registrar.menu");
String _search = bundle.getProperty("registnet.user.registrar.search");

String _data_management = bundle.getProperty("registnet.user.registrar.menuitem.data_management");
String _colleges = bundle.getProperty("registnet.user.registrar.menuitem.data_management.colleges");
String _units = bundle.getProperty("registnet.user.registrar.menuitem.data_management.units");
String _courses = bundle.getProperty("registnet.user.registrar.menuitem.data_management.courses");
String _curricula = bundle.getProperty("registnet.user.registrar.menuitem.data_management.curricula");
String _degree_courses= bundle.getProperty("registnet.user.registrar.menuitem.data_management.degree_courses");
String _students = bundle.getProperty("registnet.user.registrar.menuitem.data_management.students");
String _plan_of_courseworks = bundle.getProperty("registnet.user.registrar.menuitem.data_management.plan_of_courseworks");
String _grades = bundle.getProperty("registnet.user.registrar.menuitem.data_management.grades");
String _sections = bundle.getProperty("registnet.user.registrar.menuitem.data_management.sections");

String _registration = bundle.getProperty("registnet.user.registrar.menuitem.registration");
String _demand_prediction = bundle.getProperty("registnet.user.registrar.menuitem.registration.demand_prediction");
String _preenlistment = bundle.getProperty("registnet.user.registrar.menuitem.registration.preenlistment");

String _student_records = bundle.getProperty("registnet.user.registrar.menuitem.student_records");
String _query_page = bundle.getProperty("registnet.user.registrar.menuitem.student_records.query_page");

String _grades = bundle.getProperty("registnet.user.registrar.menuitem.grades");
String _gradesheet = bundle.getProperty("registnet.user.registrar.menuitem.grades.gradesheet");
String _removal = bundle.getProperty("registnet.user.registrar.menuitem.grades.removal");
String _completion = bundle.getProperty("registnet.user.registrar.menuitem.grades.completion");
String _change_grade = bundle.getProperty("registnet.user.registrar.menuitem.grades.change_grade");

String _summaries = bundle.getProperty("registnet.user.registrar.menuitem.summaries");
String _honorary = bundle.getProperty("registnet.user.registrar.menuitem.summaries.honorary");
String _delinquent = bundle.getProperty("registnet.user.registrar.menuitem.summaries.delinquent");
String _grade_frequency = bundle.getProperty("registnet.user.registrar.menuitem.summaries.grade_frequency");
String _classification_frequency = bundle.getProperty("registnet.user.registrar.menuitem.summaries.classification_frequency");

String _icon_home = bundle.getProperty("registnet.icons.home");

HashMap map_tab = new HashMap();
/* [end] */



/* [start]	defines an event listener;
			when a tab is closed, it is removed from the hashmap */
private class CloseTabEventListener implements EventListener {
	private String source;
	
	public CloseTabEventListener (String source){
		this.source = source;
	}
			
	public void onEvent(Event event) throws UiException {
		map_tab.remove(source);
	}
}
/* [end] */



/* [start]	retrieves session variables */
String _user = session.getAttribute("_username");
String _user_type = session.getAttribute("_user_type");
String _office = session.getAttribute("_office");
/* [end] */



/* [start]	checks if session is valid */
boolean _isValidSession = false;
try{
	_isValidSession = _user_type.equals(_registrar);
}catch(Exception e) { _isValidSession = false; }
/* [end] */



/* [start]	displays the student records module */
void showStudentRecords(){
	String object = _student_records;
	if(!map_tab.containsKey(object)){		
		Tabs tabs = stage.getTabs();
		Tab tab = new Tab(object);
		tab.setClosable(true);
		tab.setParent(tabs);
		tab.addEventListener("onClose", new CloseTabEventListener(object));
		
		Tabpanels tabpanels = stage.getTabpanels();
		Tabpanel tabpanel = new Tabpanel();
		tabpanel.setSclass("background_light_blue");
		tabpanel.setParent(tabpanels);
		stage.setSelectedPanel(tabpanel);
		
		map_tab.put(object, tab);

		Component win = Executions.createComponents("../../WEB-INF/macros/student_records/student_records.zul", tabpanel, null);		
	}
	else
		map_tab.get(object).setSelected(true);
}
/* [end] */



/* [start]	displays the grades module */
void showGrades(String object){
	if(!map_tab.containsKey(object)){		
		Tabs tabs = stage.getTabs();
		Tab tab = new Tab(object);
		tab.setClosable(true);
		tab.setParent(tabs);
		tab.addEventListener("onClose", new CloseTabEventListener(object));
		
		Tabpanels tabpanels = stage.getTabpanels();
		Tabpanel tabpanel = new Tabpanel();
		tabpanel.setSclass("background_light_blue");
		tabpanel.setParent(tabpanels);
		stage.setSelectedPanel(tabpanel);
		
		map_tab.put(object, tab);
		
		if(object.equals(_gradesheet)){
			Component win = Executions.createComponents("../../WEB-INF/macros/grades/gradesheet.zul", tabpanel, null);
		}
		else if(object.equals(_removal)){
			Component win = Executions.createComponents("../../WEB-INF/macros/grades/removal.zul", tabpanel, null);
		}
		else if(object.equals(_completion)){
			Component win = Executions.createComponents("../../WEB-INF/macros/grades/completion.zul", tabpanel, null);
		}
		else if(object.equals(_change_grade)){
			Component win = Executions.createComponents("../../WEB-INF/macros/grades/change_grade.zul", tabpanel, null);
		}
	}
	else
		map_tab.get(object).setSelected(true);
}
/* [end] */



/* [start]	displays the data management module */
void showManager(String object){
	if(!map_tab.containsKey(object)){		
		Tabs tabs = stage.getTabs();
		Tab tab = new Tab(object);
		tab.setClosable(true);
		tab.setParent(tabs);
		tab.addEventListener("onClose", new CloseTabEventListener(object));
		
		Tabpanels tabpanels = stage.getTabpanels();
		Tabpanel tabpanel = new Tabpanel();
		tabpanel.setSclass("background_light_blue");
		tabpanel.setParent(tabpanels);
		stage.setSelectedPanel(tabpanel);
		
		map_tab.put(object, tab);
		
		if(object.equals(_colleges)){
			Component win = Executions.createComponents("../../WEB-INF/macros/data_management/college.zul", tabpanel, null);
		}
		else if(object.equals(_units)){
			Component win = Executions.createComponents("../../WEB-INF/macros/data_management/unit.zul", tabpanel, null);
		}
		else if(object.equals(_courses)){
			Component win = Executions.createComponents("../../WEB-INF/macros/data_management/course.zul", tabpanel, null);
		}
		else if(object.equals(_degree_courses)){
			Component win = Executions.createComponents("../../WEB-INF/macros/data_management/degreecourse.zul", tabpanel, null);
		}
		else if(object.equals(_curricula)){
			Component win = Executions.createComponents("../../WEB-INF/macros/data_management/curriculum.zul", tabpanel, null);
		}
		else if(object.equals(_students)){
			Component win = Executions.createComponents("../../WEB-INF/macros/data_management/student.zul", tabpanel, null);
		}
		else if(object.equals(_plan_of_courseworks)){
			Component win = Executions.createComponents("../../WEB-INF/macros/data_management/plan_of_coursework.zul", tabpanel, null);
		}
		else if(object.equals(_grades)){
			Component win = Executions.createComponents("../../WEB-INF/macros/data_management/grade.zul", tabpanel, null);
		}
		else if(object.equals(_sections)){
			session.setAttribute("_office", "OUR");
			Component win = Executions.createComponents("../../WEB-INF/macros/data_management/section_configuration.zul", tabpanel, null);
		}
	}
	else
		map_tab.get(object).setSelected(true);
}
/* [end] */



/* [start]	displays the academic records module */
void showSummaries(String object){
	if(!map_tab.containsKey(object)){		
		Tabs tabs = stage.getTabs();
		Tab tab = new Tab(object);
		tab.setClosable(true);
		tab.setParent(tabs);
		tab.addEventListener("onClose", new CloseTabEventListener(object));
		
		Tabpanels tabpanels = stage.getTabpanels();
		Tabpanel tabpanel = new Tabpanel();
		tabpanel.setSclass("background_light_blue");
		tabpanel.setParent(tabpanels);
		stage.setSelectedPanel(tabpanel);
		
		map_tab.put(object, tab);
		
		if(object.equals(_honorary)){
			Component win = Executions.createComponents("../../WEB-INF/macros/summaries/honorary.zul", tabpanel, null);
		}
		else if(object.equals(_delinquent)){
			Component win = Executions.createComponents("../../WEB-INF/macros/summaries/delinquent.zul", tabpanel, null);
		}
		else if(object.equals(_grade_frequency)){
			Component win = Executions.createComponents("../../WEB-INF/macros/summaries/grade_frequency.zul", tabpanel, null);
		}
		else if(object.equals(_classification_frequency)){
			Component win = Executions.createComponents("../../WEB-INF/macros/summaries/classification_frequency.zul", tabpanel, null);
		}
	}
	else
		map_tab.get(object).setSelected(true);
}
/* [end] */



/* [start]	displays course demand */
void showCourseDemand(String object){
	if(!map_tab.containsKey(object)){		
		Tabs tabs = stage.getTabs();
		Tab tab = new Tab(object);
		tab.setClosable(true);
		tab.setParent(tabs);
		tab.addEventListener("onClose", new CloseTabEventListener(object));
		
		Tabpanels tabpanels = stage.getTabpanels();
		Tabpanel tabpanel = new Tabpanel();
		tabpanel.setSclass("background_light_blue");
		tabpanel.setParent(tabpanels);
		stage.setSelectedPanel(tabpanel);
		
		map_tab.put(object, tab);
		
		Component win = Executions.createComponents("../../WEB-INF/macros/registration/course_demand.zul", tabpanel, null);
	}
	else
		map_tab.get(object).setSelected(true);
}
/* [end] */



void showCourseOffering(String object){
	if(!map_tab.containsKey(object)){		
		Tabs tabs = stage.getTabs();
		Tab tab = new Tab(object);
		tab.setClosable(true);
		tab.setParent(tabs);
		tab.addEventListener("onClose", new CloseTabEventListener(object));
		
		Tabpanels tabpanels = stage.getTabpanels();
		Tabpanel tabpanel = new Tabpanel();
		tabpanel.setSclass("background_light_blue");
		tabpanel.setParent(tabpanels);
		stage.setSelectedPanel(tabpanel);
		
		map_tab.put(object, tab);
		
		if(object.equals("Course Offering")){
			Component win = Executions.createComponents("../../WEB-INF/macros/registration/course_offering.zul", tabpanel, null);
		}
		
	}
	else
		map_tab.get(object).setSelected(true);
}



/* [start]	displays continuing students */
void showContinuingStudents(String object){
	if(!map_tab.containsKey(object)){		
		Tabs tabs = stage.getTabs();
		Tab tab = new Tab(object);
		tab.setClosable(true);
		tab.setParent(tabs);
		tab.addEventListener("onClose", new CloseTabEventListener(object));
		
		Tabpanels tabpanels = stage.getTabpanels();
		Tabpanel tabpanel = new Tabpanel();
		tabpanel.setSclass("background_light_blue");
		tabpanel.setParent(tabpanels);
		stage.setSelectedPanel(tabpanel);
		
		map_tab.put(object, tab);
		
		Component win = Executions.createComponents("../../WEB-INF/macros/registration/continuing_students.zul", tabpanel, null);
	}
	else
		map_tab.get(object).setSelected(true);
}
/* [end] */

/* [start]	displays new freshmen */
void showNewFreshmen(String object){
	if(!map_tab.containsKey(object)){		
		Tabs tabs = stage.getTabs();
		Tab tab = new Tab(object);
		tab.setClosable(true);
		tab.setParent(tabs);
		tab.addEventListener("onClose", new CloseTabEventListener(object));
		
		Tabpanels tabpanels = stage.getTabpanels();
		Tabpanel tabpanel = new Tabpanel();
		tabpanel.setSclass("background_light_blue");
		tabpanel.setParent(tabpanels);
		stage.setSelectedPanel(tabpanel);
		
		map_tab.put(object, tab);
		
		Component win = Executions.createComponents("../../WEB-INF/macros/registration/new_freshmen.zul", tabpanel, null);
	}
	else
		map_tab.get(object).setSelected(true);
}
/* [end] */

/* [start]	displays transferee */
void showTransferee(String object){
	if(!map_tab.containsKey(object)){		
		Tabs tabs = stage.getTabs();
		Tab tab = new Tab(object);
		tab.setClosable(true);
		tab.setParent(tabs);
		tab.addEventListener("onClose", new CloseTabEventListener(object));
		
		Tabpanels tabpanels = stage.getTabpanels();
		Tabpanel tabpanel = new Tabpanel();
		tabpanel.setSclass("background_light_blue");
		tabpanel.setParent(tabpanels);
		stage.setSelectedPanel(tabpanel);
		
		map_tab.put(object, tab);
		
		Component win = Executions.createComponents("../../WEB-INF/macros/registration/transferee.zul", tabpanel, null);
	}
	else
		map_tab.get(object).setSelected(true);
}
/* [end] */


/* [start]	displays preenlistment */
void showPreenlistment(String object){
	if(!map_tab.containsKey(object)){		
		Tabs tabs = stage.getTabs();
		Tab tab = new Tab(object);
		tab.setClosable(true);
		tab.setParent(tabs);
		tab.addEventListener("onClose", new CloseTabEventListener(object));
		
		Tabpanels tabpanels = stage.getTabpanels();
		Tabpanel tabpanel = new Tabpanel();
		tabpanel.setSclass("background_light_blue");
		tabpanel.setParent(tabpanels);
		stage.setSelectedPanel(tabpanel);
		
		map_tab.put(object, tab);
		
		Component win = Executions.createComponents("../../WEB-INF/macros/registration/preenlistment.zul", tabpanel, null);
	}
	else
		map_tab.get(object).setSelected(true);
}
/* [end] */


/* [start]	displays course demand */
void showCourseDemand(String object){
	if(!map_tab.containsKey(object)){		
		Tabs tabs = stage.getTabs();
		Tab tab = new Tab(object);
		tab.setClosable(true);
		tab.setParent(tabs);
		tab.addEventListener("onClose", new CloseTabEventListener(object));
		
		Tabpanels tabpanels = stage.getTabpanels();
		Tabpanel tabpanel = new Tabpanel();
		tabpanel.setSclass("background_light_blue");
		tabpanel.setParent(tabpanels);
		stage.setSelectedPanel(tabpanel);
		
		map_tab.put(object, tab);
		
		Component win = Executions.createComponents("../../WEB-INF/macros/registration/course_demand.zul", tabpanel, null);
	}
	else
		map_tab.get(object).setSelected(true);
}
/* [end] */



/* [start]	displays Pre-Registration tab */
void showPreRegistration(String object){
	if(!map_tab.containsKey(object)){		
		Tabs tabs = stage.getTabs();
		Tab tab = new Tab(object);
		tab.setClosable(true);
		tab.setParent(tabs);
		tab.addEventListener("onClose", new CloseTabEventListener(object));
		
		Tabpanels tabpanels = stage.getTabpanels();
		Tabpanel tabpanel = new Tabpanel();
		tabpanel.setSclass("background_light_blue");
		tabpanel.setParent(tabpanels);
		stage.setSelectedPanel(tabpanel);
		
		map_tab.put(object, tab);
		
		Component win = Executions.createComponents("../../WEB-INF/macros/registration/preregistration.zul", tabpanel, null);
	}
	else
		map_tab.get(object).setSelected(true);
}
/* [end] */

/* [start]	displays Student Status tab */
void showStudentStatus(String object){
	if(!map_tab.containsKey(object)){		
		Tabs tabs = stage.getTabs();
		Tab tab = new Tab(object);
		tab.setClosable(true);
		tab.setParent(tabs);
		tab.addEventListener("onClose", new CloseTabEventListener(object));
		
		Tabpanels tabpanels = stage.getTabpanels();
		Tabpanel tabpanel = new Tabpanel();
		tabpanel.setSclass("background_light_blue");
		tabpanel.setParent(tabpanels);
		stage.setSelectedPanel(tabpanel);
		
		map_tab.put(object, tab);
		
		Component win = Executions.createComponents("../../WEB-INF/macros/registration/student_status.zul", tabpanel, null);
	}
	else
		map_tab.get(object).setSelected(true);
}
/* [end] */

/* [start]	displays Enlistme tab */
void showEnlistment(String object){
	if(!map_tab.containsKey(object)){		
		Tabs tabs = stage.getTabs();
		Tab tab = new Tab(object);
		tab.setClosable(true);
		tab.setParent(tabs);
		tab.addEventListener("onClose", new CloseTabEventListener(object));
		
		Tabpanels tabpanels = stage.getTabpanels();
		Tabpanel tabpanel = new Tabpanel();
		tabpanel.setSclass("background_light_blue");
		tabpanel.setParent(tabpanels);
		stage.setSelectedPanel(tabpanel);
		
		map_tab.put(object, tab);
		
		Component win = Executions.createComponents("../../WEB-INF/macros/registration/enlistment.zul", tabpanel, null);
	}
	else
		map_tab.get(object).setSelected(true);
}
/* [end] */


/* [start]	displays Enlistme tab */
void showEnlistmentStatistics(String object){
	new registnet.enlistment.SummaryGenerator().doGenerateSummary();
}
/* [end] */


/* [start]	signs out the user*/
void signOut(){
	session.invalidate();
	Executions.sendRedirect("../../index.zul");
}
/* [end] */